function removeOne(id){
	layer.confirm("确定要删除该角色吗?",{icon: 4, title:'确认信息'},function(index){
		layer.close(index);
		var $form=$("<form>" );
		$form.attr( "style","display:none" ).attr( "target","").attr( "method","post" )
		.attr( "action", basepath + "/subrole/del");
        var $id=$("<input>" ).attr("type" ,"hidden" ).attr("name" ,"id" ).attr("value" ,id);
		$form.append($id);
		$("body").append($form);
		$form.submit();
	},function(index){
		layer.close(index);
	});
}
function stopit(id,state){
	var msg = state==0?"停用":"启用";
	layer.confirm("确定要"+msg+"角色吗?",{icon: 4, title:'确认信息'},function(index){
		$.post(basepath+"/subrole/stopit",{id:id,status:state},function(data){
			if(data.status==200){
				layer.msg("角色已"+msg+"！", function(){
					location.reload(true);
				});
			}
		}, "json");
	},function(index){
		layer.close(index);
	});
}

function loading(){
	return layer.msg('处理中，请稍后...', {icon: 16,shade: [0.5, '#393D49'],time:0});
}

var template = document.getElementById('script_template').innerHTML;
Mustache.parse(template);

function authrize(id){
	window.itemId = id;
	var index = loading();
	$.post(basepath+"/subrole/wxs",{"roleId":id},function(data){
		var rendered = "";
		if(null!=data){
			rendered=Mustache.render(template, data);
			layer.close(index);
			window.layerIndex=layer.open({
			    type: 1,
			    title: '用户微信号',
			    shadeClose: false,
			    shade: 0.8,
			    scrollbar:false,
			    area: ['420px', '60%'],
			    content: rendered
			}); 
		}
		
	},"json");
}
function doAuth(that){
	var $perm = $(that).closest("table").find(":checkbox:checked");
	var permArray = new Array();
	$perm.each(function(){
		permArray.push(this.value);
	});
	var index = loading();
	$.post(basepath+"/subrole/auth",{"roleId":window.itemId,"perm":permArray},function(data){
		layer.close(layerIndex);
		layer.close(index);
		if(data.status==200){
			layer.msg("授权成功");
		}else{
			layer.msg("授权异常");
		}
	});
}
function selectAll(isTrue, that){
	var $perm = $(that).closest("table").find(":checkbox");
	$perm.each(function(){
		if(isTrue){
			this.checked=true;
		}else{
			this.checked=false;
		}
	});
}

//菜单权限管理
function configMenu(id){
	window.roleId = id;
	var index = loading();
	$.get(basepath+"/subrole/role/wxs",{"roleId":id},function(data){
		var rendered = "";
		if(null!=data){
			var template1 = document.getElementById('script_template_1').innerHTML;
			rendered=Mustache.render(template1, data);
			layer.close(index);
			window.layerIndex=layer.open({
			    type: 1,
			    title: '用户微信号',
			    shadeClose: false,
			    shade: 0.8,
			    scrollbar:false,
			    area: ['450px', '60%'],
			    content: rendered
			}); 
		}
		
	},"json");
}
function manageMenu(wxid){
	var roleId = window.roleId;
	layer.close(window.layerIndex);
	window.layerIndex=layer.open({
	    type: 2,
	    title: '用户微信号',
	    shadeClose: false,
	    shade: 0.8,
	    scrollbar:false,
	    area: ['380px', '70%'],
	    content: basepath+"/subrole/role/wx/menus?roleId="+roleId+"&wxId="+wxid
	}); 
}
function authFun(ids, wxId, roleId){
	layer.close(layerIndex);
	var index = loading();
	if(""==ids){
		layer.close(index);
		layer.msg("未做权限修改！");
		return false;
	}
	$.post(basepath+"/subrole/role/wx/menus",{wxId:wxId,roleId:roleId, mids:ids}, function(data){
		if(data.state==200){
			layer.close(index);
			layer.msg("授权成功");
		}else{
			layer.close(index);
			layer.msg("授权异常");
		}
	},"json");
}